package com.ruoyi.project.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.domain.Correct;
import com.ruoyi.project.business.service.ICorrectService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 批改管理Controller
 *
 * @author hongwj
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/business/correct" )
@Slf4j
public class CorrectController extends BaseController {
    @Autowired
    private ICorrectService correctService;

    /**
     * 查询批改管理列表
     */
    //@PreAuthorize("@ss.hasPermi('business:correct:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(Correct correct) {
        startPage();
        List<Correct> list = correctService.selectCorrectList(correct);
        return getDataTable(list);
    }

    /**
     * 查询所有批改管理列表
     */
    //@PreAuthorize("@ss.hasPermi('business:correct:all')" )
    @Log(title = "批改管理" , businessType = BusinessType.OTHER)
    @GetMapping("/all/corrects" )
    public AjaxResult all(Correct correct) {
        List<Correct> list = correctService.selectCorrectList(correct);
        return success(list);
    }

    /**
     * 导出批改管理列表
     */
    //@PreAuthorize("@ss.hasPermi('business:correct:export')" )
    @Log(title = "批改管理" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, Correct correct) {
        List<Correct> list = correctService.selectCorrectList(correct);
        ExcelUtil<Correct> util = new ExcelUtil<Correct>(Correct. class);
        util.exportExcel(response, list, "批改管理数据" );
    }

    /**
     * 获取批改管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:correct:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return success(correctService.selectCorrectById(id));
    }

    /**
     * 新增批改管理
     */
    //@PreAuthorize("@ss.hasPermi('business:correct:add')" )
    @Log(title = "批改管理" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Correct correct) {
        log.info("Received correct data: {}", correct);
        return toAjax(correctService.insertCorrect(correct)); }

    /**
     * 修改批改管理
     */
    //@PreAuthorize("@ss.hasPermi('business:correct:edit')" )
    @Log(title = "批改管理" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Correct correct) {
        return toAjax(correctService.updateCorrect(correct));
    }

    /**
     * 删除批改管理
     */
    //@PreAuthorize("@ss.hasPermi('business:correct:remove')" )
    @Log(title = "批改管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(correctService.deleteCorrectByIds(ids));
    }
}
